Skip to content

Add file-level scanner for Linux kernel module (.ko) metadata - #5249

Open
OctavioValdiviaMendoza wants to merge 24 commits into
aboutcode-org:developfrom
OctavioValdiviaMendoza:feat/625-lkm-package-parser
Open

Add file-level scanner for Linux kernel module (.ko) metadata#5249
OctavioValdiviaMendoza wants to merge 24 commits into
aboutcode-org:developfrom
OctavioValdiviaMendoza:feat/625-lkm-package-parser

Conversation

@OctavioValdiviaMendoza

@OctavioValdiviaMendoza OctavioValdiviaMendoza commented Jul 27, 2026

Copy link
Copy Markdown

Fixes #625

This PR adds file-level scanning of metadata embedded in compiled Linux Kernel Module (.ko) files.

Implementation

A new LinuxKernelModuleScanner is implemented in scancode/plugin_lkm.py using ScanCode's file-level ScanPlugin architecture.

The scanner:

  • Is enabled with the --lkm option.
  • Uses pyelftools to open .ko files as ELF files.
  • Locates the .modinfo ELF section.
  • Parses its NUL-terminated key=value entries.
  • Preserves repeated fields such as author, alias, and firmware as lists.
  • Stores the extracted metadata in the file Resource's linux_kernel_module attribute.
  • Normalizes the .modinfo depends value into a simple list of required kernel-module names.

For example:

{
  "linux_kernel_module": {
    "license": ["GPL"],
    "author": ["Example Author"],
    "depends": ["video", "backlight"]
  }
}

Tests

Test coverage includes:

  • .modinfo extraction.
  • Repeated metadata values.
  • Required module-name parsing.
  • Unrelated files.
  • Invalid ELF files.
  • Plugin enablement and Resource attribute declaration.
  • End-to-end --lkm output.
  • Verification that no package_data is created.

Tasks

  • Reviewed contribution guidelines
  • PR is descriptively titled 📑 and links the original issue above 🔗
  • Tests pass
  • Commits are in a uniquely named feature branch and have no merge conflicts 📁
  • Updated CHANGELOG.rst (if applicable)
  • Updated documentation pages (if applicable)

@OctavioValdiviaMendoza OctavioValdiviaMendoza changed the title Add Package Parser for Linux Kernel Module (.ko) files Add file-level scanner for Linux kernel module (.ko) metadata Aug 6, 2026
OctavioValdiviaMendoza and others added 6 commits August 17, 2026 10:31
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
…ata using .modinfo section found in ELF files to yield the module macros

Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
…s that are now passed to PackageData

Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
…y DependecyPackage and PAckageData are structured correctly

Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
Add Linux Kernel Module package parser

Add support for parsing Linux Kernel Module (.ko) files.
Add pyelftools as a runtime dependency for reading ELF
.modinfo sections, register the new handler, and add
unit tests.
@OctavioValdiviaMendoza
OctavioValdiviaMendoza force-pushed the feat/625-lkm-package-parser branch from 3d3746b to 1c40b49 Compare August 17, 2026 17:33
@TaslimOseni
TaslimOseni force-pushed the feat/625-lkm-package-parser branch from 1c598fd to 385ce41 Compare August 24, 2026 16:13
diana-galeana and others added 18 commits August 26, 2026 06:26
…km.py

Add self to AUTHORS.rst

Signed-off-by: diana-galeana <162429082+diana-galeana@users.noreply.github.com>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
In case of referenced license files, update the logic to not follow
and de-reference licenses when all the license leys in the referenced
files are already present in the main license detection. This preserves
the license conditions in case there are extra license keys in an
expression.

Reference: aboutcode-org#3523
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Vincent Gao <gaobing1230@gmail.com>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Deprecate --ingore and --include pre-scan plugins and move the
ignore/include functionality to codebase import stage to get rid
of multiple codebase walks.

Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
For multiple inputs, do not walk outside the input paths, from their
common prefix. Instead create only the directory relationships between
the common prefix and input paths and start the codebase walk from
every input paths.

Also deprecate --include options to only support ignoring paths
through path patterns.

Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Install commoncode from local source code instead of released
commoncode so this can be installed/tested directly. Also add
tests for released commoncode via azure pipelines.

Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: Ayan Sinha Mahapatra <asmahapatra@aboutcode.org>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
Signed-off-by: OctavioValdiviaMendoza <octavio.valdiviamendoza@sjsu.edu>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
…lugin

Signed-off-by: Taslim Oseni <tasleemoseni@gmail.com>
Signed-off-by: diana-galeana <dgaleana07@gmail.com>
@diana-galeana
diana-galeana force-pushed the feat/625-lkm-package-parser branch from 385ce41 to b2ec8e1 Compare August 26, 2026 06:34
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Package parser for LKMs

5 participants